<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
		<style>
			.box {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 200px;
				height: 200px;
				background-color: orange;
			}

			.box span {
				width: 100px;
				height: 100px;
				background-color: red;
			}
		</style>
	</head>
	<body>
		<div class="box">
			<span></span>
		</div>

		<script>
			var body = document.body
			var boxEl = document.querySelector('.box')
			var spanEl = document.querySelector('.box span')

			// 事件冒泡过程
			/* spanEl.addEventListener('click', function () {
				console.log('span被点击了')
			})

			boxEl.addEventListener('click', function () {
				console.log('div被点击了')
			})

			body.addEventListener('click', function () {
				console.log('body被点击了')
			}) */

			// 事件捕获过程
			spanEl.addEventListener(
				'click',
				function () {
					console.log('span被点击了')
				},
				true
			)

			boxEl.addEventListener(
				'click',
				function () {
					console.log('div被点击了')
				},
				true
			)

			body.addEventListener(
				'click',
				function () {
					console.log('body被点击了')
				},
				true
			)
		</script>
	</body>
</html>
